from selenium import webdriver
from selenium.webdriver.common.by import By
import time

driver = webdriver.Edge()

# 警告框
driver.get('E:\python爬虫\python-web-crawler-learning\第5章 抓取动态网页数据\警告框.html')
driver.find_element(By.TAG_NAME, 'button').click()
alert = driver.switch_to.alert  # 选中警告框
print(alert.text)  # 输出警告框文本内容
time.sleep(1)
alert.accept()  # 单击“确认”按钮

# 确认框
driver.get('E:\python爬虫\python-web-crawler-learning\第5章 抓取动态网页数据\确认框.html')
driver.find_element(By.TAG_NAME, 'button').click()
alert = driver.switch_to.alert  # 选中确认框
time.sleep(1)
alert.dismiss()  # 单击“取消”按钮

# 提示框
driver.get('E:\python爬虫\python-web-crawler-learning\第5章 抓取动态网页数据\提示框.html')
driver.find_element(By.TAG_NAME, 'button').click()
alert = driver.switch_to.alert      # 选中提示框
time.sleep(1)
alert.send_keys('张三')           # 接收用户输入内容
alert.accept()          # 单击“确定”按钮
